<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">

    </script>
        </head>
<body>

<p><input type="file" id="upfile"></p>
<p><input type="button" id="upJS" value="用原生JS上传"></p>


<script>
    /*原生JS版*/
    document.getElementById("upJS").onclick = function() {
        /* FormData 是表单数据类 */
        var fd = new FormData();
        var ajax = new XMLHttpRequest();
        /* 把文件添加到表单里 */
        fd.append("avatar", document.getElementById("upfile").files[0]);
        ajax.open("post", "upload", true);

        ajax.onload = function () {
            if(ajax.status == 200){
                alert(ajax.responseText);
            }
            else {
                alert(ajax.responseText);

            }
        };

        ajax.send(fd);

    }

</script>

</body>
</html>